package com.p2p.auth.service.repository;

import com.p2p.auth.common.enums.ArticleOnTopType;
import com.p2p.auth.common.enums.ArticleStatus;
import com.p2p.auth.common.enums.ArticleType;
import com.p2p.auth.domain.entity.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Antinomy on 16/11/16.
 */

@Repository
public interface ArticleRepository extends JpaRepository<Article, Long> {

    Page<Article> findByTypeInAndStatusAndOnTop(List<ArticleType> typeList, ArticleStatus status, ArticleOnTopType onTop, Pageable pageable);

    Page<Article> findByTypeInAndStatusAndOnTopOrderByEventDateDesc(List<ArticleType> typeList, ArticleStatus status, ArticleOnTopType onTop, Pageable pageable);

    Page<Article> findByTypeAndStatus(ArticleType articleType, ArticleStatus status, Pageable pageable);

    Page<Article> findByTypeAndStatusOrderByEventDateDesc(ArticleType articleType, ArticleStatus status, Pageable pageable);

    List<Article> findByTypeAndStatus(ArticleType articleType, ArticleStatus status);

    List<Article> findByTypeAndStatusNotLike(ArticleType articleType, ArticleStatus status);

    Article findByUuid(String uuid);

    List<Article> findByTypeAndStatusOrderByDisplayOrderAsc(ArticleType articleType, ArticleStatus status);

    Page<Article> findAll(Specification<Article> articleSpecification, Pageable page);
}